import requests


class AddTemp(object):
    @classmethod
    def add_temp(cls, header, json_data):
        url = "http://ihrm-test.itheima.net/api/sys/user"
        resp_add = requests.post(url=url, headers=header, json=json_data)
        return resp_add

    @classmethod
    def query_temp(cls, temp_id, header):
        url_query = "http://ihrm-test.itheima.net/api/sys/user/" + temp_id
        resp_query = requests.get(url=url_query, headers=header)
        return resp_query

    @classmethod
    def updata_temp(cls, temp_id, header, updata_data):
        url_updata = "http://ihrm-test.itheima.net/api/sys/user/" + temp_id
        resp_updata = requests.put(url=url_updata, headers=header, json=updata_data)
        return resp_updata

    @classmethod
    def del_temp(cls, temp_id, header):
        url_del = "http://ihrm-test.itheima.net/api/sys/user/" + temp_id
        resp_del = requests.delete(url=url_del, headers=header)
        return resp_del


if __name__ == '__main__':
    head = {"Content-Type": "application/json",
            "Authorization": "Bearer adb79083-3bb7-4b93-8b93-07c3a884a485"}
    json_data = {
        "username": "小猪佩奇",
        "mobile": "13117456243",
        "workNumber": "9527"
    } 
    resp = AddTemp.add_temp(head, json_data)
    print(resp.json())
    id = "1539971211298111488"
    print(AddTemp.query_temp(id, head).json())
    updata = {"username": "猪奇"}
    print(AddTemp.updata_temp(id, head, updata).json())
    resp=AddTemp.del_temp(id, head)
    print(resp.json())